<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Navigation model for the navigation module.
 * 
 * @author		Phil Sturgeon
 * @author		PyroCMS Dev Team
 * @package		PyroCMS\Core\Modules\Navigation\Models
 */
class Tour_m extends MY_Model
{
	
	public function __construct()
	{
		parent::__construct();
		
	}
	
	/**
	 * Get Tour Record with four rows
	 *
	 * 
	 * @param select * from default_tbl_tour limit 4
	 * @return $query->result();
	 */
	public function getFourTour()
	{
		//$query = $this->db->get('tbl_tour',4);
		$query = $this->db->query("SELECT
					t.*
					FROM
					default_tbl_tour AS t
					ORDER BY
					t.id DESC
					LIMIT 4
				") or die(mysql_error());

		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	}
	
	/**
	 * Get All record from Tour
	 * @param select *from default_tbl_tour
	 * @return $query->result();
	 */
public function tour_count() {
	return $this->db->count_all("tbl_tour");
    }
public function getAllTour($limit,$start)
	{
		$this->db->limit($limit, $start);
		$query = $this->db->get('tbl_tour');

		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	}
	
public function getAllById($id){
	
	$query = $this->db->get_where('tbl_tour',array('id'=>$id));

		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
/*public function phnompenh_count() {
	return $this->db->count_all("tbl_tour");
    }*/
public function getAllHotelPhnomPenh(){//@parameter $id_hotel_map=1 for Phnom Penh
	$query = $this->db->query("SELECT
				hm.title,
				t.*
				FROM
				default_tbl_hotel_map AS hm
				INNER JOIN default_tbl_tour AS t ON t.id_hotel_map = hm.id_hotel_map
				WHERE hm.etat_doc=1
				AND hm.visible=1
				AND t.id_hotel_map=1"
				);
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
public function getAllHotelSiemReap(){//@parameter $id_hotel_map=2 for Siem Reap
	$query = $this->db->query("SELECT
				hm.title,
				t.*
				FROM
				default_tbl_hotel_map AS hm
				INNER JOIN default_tbl_tour AS t ON t.id_hotel_map = hm.id_hotel_map
				WHERE hm.etat_doc=1
				AND hm.visible=1
				AND t.id_hotel_map=2"
				);
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}	
public function getAllHotelSihanouk(){//@parameter $id_hotel_map=3 for Sihnouk Ville
	$query = $this->db->query("SELECT
				hm.title,
				t.*
				FROM
				default_tbl_hotel_map AS hm
				INNER JOIN default_tbl_tour AS t ON t.id_hotel_map = hm.id_hotel_map
				WHERE hm.etat_doc=1
				AND hm.visible=1
				AND t.id_hotel_map=3"
				);
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
public function package_count() {
	return $this->db->count_all("tbl_package_tour");
    }
public function getAllPackage($limit=null, $start=null){//@parameter package tour for package tour menu
	$this->db->limit($limit, $start);
	$query = $this->db->get_where("tbl_package_tour",array('id_package_map'=>1)) or die(mysql_error());
	/*$query = $this->db->query("SELECT pt.* FROM 
					default_tbl_package_tour as pt
					LEFT JOIN default_tbl_package_map as pm ON pt.id_package_map = pm.id_package_map
					WHERE
					pm.id_package_map = 1
					AND pt.visible=1
					AND pt.etat_doc=1
					LIMIT $limit, $start"
				);*/
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
public function get4Packages(){//@parameter package tour for package tour menu
	$query = $this->db->get('tbl_package_tour',4);
	$query=$this->db->Query("SELECT
					pt.*,
					pm.title as title_pm
					FROM
					default_tbl_package_tour AS pt
					INNER JOIN default_tbl_package_map as pm ON pt.id_package_map = pm.id_package_map
					WHERE pm.id_package_map=1
					AND pm.etat_doc=1
					AND pm.visible=1
					LIMIT 4") or die(mysql_error());
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
//-------pagination----------//
public function campbodiaCount() {
	return $this->db->count_all("tbl_cambodia_page");
    }
public function getAllCambodia($limit,$start){
//@parameter package tour for package tour menu
	$this->db->limit($limit, $start);
	$query = $this->db->get("tbl_cambodia_page") or die(mysql_error());

		if ($query->num_rows() > 0) {
		foreach ($query->result() as $row) {
		                $data[] = $row;
		            }
		return $data;
		        }
	
	/*$query = $this->db->query("SELECT
						cp.*
						FROM
						default_tbl_cambodia_page AS cp
						WHERE cp.etat_doc=1
						AND cp.visible=1"
				);
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}*/
	
}
public function getListSubPackages(){//@parameter $id_hotel_map=3 for Sihnouk Ville
	$query = $this->db->query("SELECT
				nl.*
				FROM
				default_navigation_links AS nl
				WHERE
				nl.parent = 12
				AND nl.navigation_group_id=1
			"
				);
		if ($query->num_rows() == 0)
		{
			return FALSE;
		}
		else
		{
			return $query->result();
		}
	
}
	
}